class Feed::AfterServiceFinished < Feed
  validates :order_item_id,
    :after_service_id,
    :presence => true
  
  after_destroy do |feed|
    feed.order_item.try(:reset_feed!)
    feed.after_service.update_gathered_balance!
    feed.order_item.reset_after_serviced_cost!
  end

  def code
    ActiveSupport::StringInquirer.new('after_service_finished')
  end

  def short_desc
    desc = "#{after_service.installer_full_name}于#{after_service.after_serviced_on}上门<b>服务</b>【#{
          after_service.order_item.furniture_code}-#{after_service.order_item.furniture_name}】 售后成本￥#{
          format("%.2f",after_service.after_serviced_cost)}"
    if after_service.gathered_balance > 0
      desc += "  收款￥#{format("%.2f",after_service.gathered_balance)}"
    end
    return desc
  end

  def remark
    after_service.installed_remark
  end

  def related_one
    after_service
  end

  def related_html_id
    "related_after_service_#{after_service.id}"
  end

  def related_type
    "related_after_service"
  end
end
